package com.fr.data.impl;

import com.fr.base.FRContext;
import com.fr.base.XMLable;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.core.DataUtils;
import com.fr.report.web.event.Listener;
import com.fr.report.web.ui.Widget;
import com.fr.report.web.ui.WidgetConfig;
import com.fr.report.web.ui.WidgetManager;
import com.fr.web.Repository;

public class NameWidget extends Widget
  implements XMLable
{
  private String name;
  private transient Widget _widget;

  public NameWidget()
  {
  }

  public NameWidget(String paramString)
  {
    this.name = paramString;
  }

  public String getName()
  {
    return this.name;
  }

  private Widget createWidget()
  {
    WidgetManager localWidgetManager = FRContext.getWidgetManager();
    try
    {
      this._widget = DataUtils.getClonedWidgetConfig(localWidgetManager, this.name).toWidget();
      copyProperty(this._widget);
    }
    catch (Exception localException)
    {
      throw new RuntimeException(localException.getMessage(), localException);
    }
    return this._widget;
  }

  private void copyProperty(Widget paramWidget)
  {
    paramWidget.setWidgetName(this.widgetName);
    paramWidget.setDisabled(this.disabled);
    paramWidget.setInvisible(this.invisible);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof NameWidget) && (this.name.equals(((NameWidget)paramObject).name)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }

  public String getXType()
  {
    return createWidget().getXType();
  }

  public boolean isEditor()
  {
    return createWidget().isEditor();
  }

  public String getWidgetName()
  {
    return createWidget().getWidgetName();
  }

  public String[] supportedEvents()
  {
    return new String[0];
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    return createWidget().createJSONConfig(paramObject, paramRepository);
  }

  public Listener[] createListeners(Repository paramRepository)
  {
    return createWidget().createListeners(paramRepository);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && ("Name".equals(paramXMLableReader.getTagName())))
    {
      String str;
      if ((str = paramXMLableReader.getElementValue()) != null)
        this.name = str;
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Name").textNode(this.name).end();
  }

  public String toString()
  {
    return "Widget[" + this.name + "]";
  }
}